package com.projecy.config.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 时间自动填充
     * 2021-07-31MyMetaObjectHandler时间自动填充拦截器
     *  地址：https://blog.csdn.net/m0_55548657/article/details/119279414
     * */
    

    @Override//自动填充createTime
    public void insertFill(MetaObject metaObject) {
        System.out.println("填充createTime");
        this.strictInsertFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class);
    }


    @Override//自动填充updateTime
    public void updateFill(MetaObject metaObject) {
        System.out.println("填充updateTime");
        this.strictUpdateFill(metaObject, "updateTime", () -> LocalDateTime.now(), LocalDateTime.class);
    }
}
